{{- /* Collection List */ -}}
{{- $params := partial "function/params.html" -}}

{{- if .Params.collections | and $params.collectionList | and (not $params.password) -}}
  {{- $collectionTerms := .GetTerms "collections" -}}
  {{- range $collectionTerms -}}
    {{- $pages := (where .Pages "Params.Weight" "!=" nil) | append (where .Pages "Params.Weight" "eq" nil).ByDate -}}
    {{- $open := eq (index $collectionTerms 0) . -}}
    {{- $currentKey := 0 -}}

    <div class="details collection-details{{ if $open }} open{{ end }}">
      <div class="details-summary collection-summary">
        {{ dict "Class" "fa-solid fa-layer-group fa-fw" | partial "plugin/icon.html" }}
        <span class="collection-name" data-collections="{{ T "collections" }}">{{ .LinkTitle }}</span>
        <span class="collection-count">{{ $pages.Len }}</span>
        {{- dict "Class" "details-icon fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
      </div>
      <div class="details-content collection-content">
        <nav>
          <ul class="collection-list">
            {{- range $key, $value := $pages -}}
              {{- $title := title $value.LinkTitle -}}
              {{- if $value.LinkTitle | eq $.LinkTitle -}}
                {{- $currentKey = $key -}}
                <li class="collection-item"><span class="active" title="{{ $title }}">{{ $title }}</span></li>
              {{- else }}
                <li class="collection-item"><a href="{{ $value.RelPermalink }}" title="{{ $title }}">{{ $title }}</a></li>
              {{- end }}
            {{- end -}}
          </ul>
          <div class="collection-nav-simple">
            {{- with $pages.Next $ -}}
              <a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ title .LinkTitle }}">
                {{- dict "Class" "fa-solid fa-angle-left fa-fw" | partial "plugin/icon.html" -}}
              </a>
            {{- else -}}
              {{- dict "Class" "fa-solid fa-angle-left fa-fw collection-nav-item text-secondary" | partial "plugin/icon.html" -}}
            {{- end -}}
            <span class="text-secondary">{{ add $currentKey 1 }}/{{ $pages.Len }}</span>
            {{- with $pages.Prev $ -}}
              <a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ title .LinkTitle }}">
                {{- dict "Class" "fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
              </a>
            {{- else -}}
              {{- dict "Class" "fa-solid fa-angle-right fa-fw collection-nav-item text-secondary" | partial "plugin/icon.html" -}}
            {{- end -}}
          </div>
        </nav>
      </div>
    </div>
  {{- end -}}
{{- end -}}
